home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 3
/
Info_Mac_1994-01.iso
/
Development
/
Source
/
MSG Graphic Effects 1.0 Source
/
Hilbert wipe.c
< prev
next >
Wrap
Text File
|
1993-08-23
|
3KB
|
114 lines
/*******************************************************************************
* Copyright © 1992-1993 Mark Pilgrim *
* *
* This file is provided as is, and may be freely distributed unaltered. This *
* message must accompany any copy of this file. This file may be used or *
* modified for use for a non-commercial product provided that appropriate *
* credit is given to the author named above. *
* Commercial use of this source code is prohibited. *
******************************************************************************/
#include "msg misc.h"
#include "msg timing.h"
/* This fills the screen by a Hilbert space-filling curve, which is defined by
two mutually recursive drawing functions:
X = left, Y, draw, right, X, draw, X, right, draw, Y, left
Y = right, X, draw, left, Y, draw, Y, left, draw, X, right
Start by drawing X at the highest recursion level from the bottomleft of the
screen. (At recursion level 1, X and Y are null functions.)
*/
#define RecursionLevel 4
#define vBlockSize 20 /* ceiling(MAIN_WINDOW_HEIGHT / 2^RecursionLevel) */
#define hBlockSize 32 /* ceiling(MAIN_WINDOW_WIDTH / 2^RecursionLevel) */
#define CorrectTime 1
typedef char Hilby[11];
Hilby HilbertPattern[]=
{
{
0x02,0x69,0x00,0x01,0x42,0x00,0x42,0x01,0x00,0x69,0x02
},
{
0x01,0x42,0x00,0x02,0x69,0x00,0x69,0x02,0x00,0x42,0x01
}
};
int direction=0;
void HilbertWipe(GrafPtr, int, int, int*, int*);
void HilbertWipeCall(GrafPtr);
void HilbertWipe(GrafPtr myGrafPtr, int level, int whichpattern, int* x, int* y)
{
int i;
Rect source;
for (i=0; i<11; i++)
{
switch (HilbertPattern[whichpattern][i])
{
case 0x01: /* turn left */
direction--;
if (direction<0) direction=3;
break;
case 0x02: /* turn right */
direction++;
if (direction==4) direction=0;
break;
case 0x00: /* draw */
StartTiming();
source.top=*y-vBlockSize;
source.bottom=*y;
source.left=*x;
source.right=*x+hBlockSize;
CopyBits(&(myGrafPtr->portBits), &(gMainWindow->portBits),
&source, &source, 0, 0L);
switch (direction)
{
case 0:
*x+=hBlockSize;
break;
case 1:
*y-=vBlockSize;
break;
case 2:
*x-=hBlockSize;
break;
case 3:
*y+=vBlockSize;
break;
}
TimeCorrection(CorrectTime);
break;
case 0x42: /* call X */
if (level>1) HilbertWipe(myGrafPtr,level-1,0,x,y);
break;
case 0x69: /* call Y */
if (level>1) HilbertWipe(myGrafPtr,level-1,1,x,y);
break;
}
}
}
void HilbertWipeCall(GrafPtr myGrafPtr)
{
int curx, cury;
Rect source;
cury=MAIN_WINDOW_HEIGHT;
curx=0;
HilbertWipe(myGrafPtr,RecursionLevel,0,&curx,&cury);
source.bottom=MAIN_WINDOW_HEIGHT;
source.right=MAIN_WINDOW_WIDTH;
source.top=source.bottom-vBlockSize;
source.left=source.right-hBlockSize;
CopyBits(&(myGrafPtr->portBits), &(gMainWindow->portBits),
&source, &source, 0, 0L); /* in case we missed any bits */
}